package com.xqboss.system.domain.dto;

import com.xqboss.common.utils.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author Trent
 * @date 2023/9/11
 */
public class StringArrayConfigKey implements SysConfigKey<List<String>> {

    private final String key;

    public StringArrayConfigKey(String key){
        this.key = key;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public List<String> convertValue(String value) {
        List<String> result = new ArrayList<>();
        if(StringUtils.isNotEmpty(value)){
            String[] split = value.split(",");
            result.addAll(Arrays.asList(split));
        }
        return result;
    }

    @Override
    public String getValue(List<String> value) {
        if(value == null){
            return null;
        }
        return String.join(",", value);
    }
}
